$(document).ready(function () {
    $.validator.setDefaults({
        submitHandler: function (val) {
            // oktipsoption = {
            //     type: 1,
            //     url: $('.formsub').attr('url'),
            //     msg: '提交成功'
            // };
            // ajaxform.init(oktipsoption, '.formsub');
            // ajaxform.submit();
            $("#agreeSubmit").ajaxSubmit({
                type: 'post',
                url: $('#startsignserviceurl').val(),
                beforeSend: function () {
                    layer.msg('正在生成合同，请稍等！', {
                        icon: 16
                        , shade: 0.01
                    });
                },
                success: function (data) {

                    //获取父层  
                    //var index = parent.layer.getFrameIndex(window.name);
                    //刷新父层  
                    // parent.location.reload();  
                    //关闭弹出层  
                    parent.layer.closeAll();
                    if (data.error == 0)
                    {
                        
                        window.location.href = $('#signserviceurl').val() + '?contractid=' + data.result.contractid;
                    } else
                    {
                        alert('发生错误请重试')
                    }


                }
            })
        },
        errorPlacement: function (error, element) {
            element.parents('.l_b').append(error);
            element.prop('placeholder', '');
        }
    });

    var record;
    // 范围要求在大于等于0，小于等于9999999999.99之间
    $("#id1,#id2").on('keyup', function () {
        var myThis = $(this);
        var val = myThis.val();
        var decimalReg = /^\d{0,999}\.{0,1}(\d{1,2})?$/;
        if (val != '' && decimalReg.test(val)) {
            record = val;
        } else {
            if (val != '') {
                myThis.val(record);
            }
        }
        myThis.blur(function () {
            record = '';
        });
    });


    $(".agree_content input,.agree_box table input").focus(function () {
        $(this).next('label.error').hide();
    })


    $("#agreeSubmit").validate({
        rules: {
            id1: {
                required: true
            },
            id2: {
                required: true
            },
            id4: {
                required: true
            },
            id5: {
                required: true
            }
        },
        messages: {
            id1: {
                required: '请填写平台服务费'
            },
            id2: {
                required: '请填写远程监管费'
            },
            id4: {
                required: '请填写法定代表人'
            },
            id5: {
                required: '请填写法定代表人'
            }
        },
        focusInvalid: false,
        onkeyup: false
    });
    $('.btn').click(function () {
        if ($("#agreeSubmit").validate().element($("#id1")) == false ) {
            window.location.href = '#errorBox'
        }
    })

})